package com.tron.io;

import java.io.ByteArrayInputStream;

public class InputStreamStart {
    public static void main(String[] args) throws Exception {
        // 输入流
        ByteArrayInputStream defaultStream = new ByteArrayInputStream("高".getBytes());
        System.out.println(defaultStream.read());  //233
        System.out.println(defaultStream.read());  //171
        System.out.println(defaultStream.read());  //152
        System.out.println(defaultStream.read());  //-1
        defaultStream.close();

        ByteArrayInputStream utf8Stream = new ByteArrayInputStream("高".getBytes("UTF-8"));
        System.out.println(utf8Stream.read()); //233
        System.out.println(utf8Stream.read()); //171
        System.out.println(utf8Stream.read()); //152
        System.out.println(utf8Stream.read()); //-1
        utf8Stream.close();

        ByteArrayInputStream gbkStream = new ByteArrayInputStream("高".getBytes("GBK"));
        System.out.println(gbkStream.read()); //184
        System.out.println(gbkStream.read()); //223
        System.out.println(gbkStream.read()); //-1
        System.out.println(gbkStream.read()); //-1
        gbkStream.close();

        // 判断一个流是否可以被打标记
        System.out.println("=================标记流");
        ByteArrayInputStream markStream = new ByteArrayInputStream("高".getBytes());
        boolean b = markStream.markSupported();
        System.out.println(b); //true
        System.out.println(markStream.read());
        System.out.println("===标记位置");
        markStream.mark(3);
        System.out.println(markStream.read());
        System.out.println(markStream.read());
        System.out.println("===重置到位置");
        markStream.reset();
        System.out.println(markStream.read());


    }
}
